package xml;

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Map;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import xmlModel.DBRoot;

public class XmlHelper {

	public static String writeString(Map<String, Object> map) {
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		XMLEncoder xmlEncoder = new XMLEncoder(bos);
		xmlEncoder.writeObject(map);
		xmlEncoder.flush();
		return bos.toString();
	}
	
	public static Map<String, Object> readString(String serializedMap) {
		XMLDecoder xmlDecoder = new XMLDecoder(new ByteArrayInputStream(serializedMap.getBytes()));
		Map<String, Object> parsedMap = (Map<String, Object>) xmlDecoder.readObject();
		return parsedMap;    
	}
}
